#ifndef _MESSAGE_MAILBOX_H
#define _MESSAGE_MAILBOX_H

#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <semaphore.h>
#include <stdint.h>

typedef enum {
    MB_EOK = 0,
    MB_ENOMEM = -1,
}mb_err_t;

typedef struct {
    sem_t blank_sem;                // 队列空信号量
    sem_t data_sem;                 // 队列满信号量
    uint32_t *buffer;               // 存放数据的缓冲区
    int32_t read_index;             // 读指针
    int32_t write_index;            // 写指针
    int32_t capacity;               // 队列容量
    pthread_mutex_t producer_lock;  // 生产者互斥锁
    pthread_mutex_t consumer_lock;  // 消费者互斥锁
} mailbox_t;

mb_err_t mb_init(mailbox_t *mb, int32_t capacity);
mb_err_t mb_destroy(mailbox_t *mb);
mb_err_t mb_send_wait(mailbox_t *mb, uint32_t value);
mb_err_t mb_recv_wait(mailbox_t *mb, uint32_t *value);

#endif